//
//  RootViewController.m
//  ExpressData
//
//  Created by user on 10/30/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"
#import "ExpressDataAppDelegate.h"
#import "AboutViewController.h"
#import "ContactCenterMapViewController.h"
#import "NewsCenterViewController.h"
#import "LoginViewController.h"

#define NoOfSection 1;
#define rowHeight  70.0f;
#define LoginRow 0
#define NewsCenterRow 1
#define ContactRow 2
#define AboutUsRow 3

@implementation RootViewController
@synthesize cellIconNames;

#pragma mark -
#pragma mark View lifecycle
NSMutableArray *listOfItems;
NSArray	*cellIconNames;

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
	
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
	listOfItems = [[NSMutableArray alloc] init];
	
	[listOfItems addObject:@"Login"];
	[listOfItems addObject:@"News Center"];
	[listOfItems addObject:@"Contact Center"];
	[listOfItems addObject:@"About Us"];
	
	[self setCellIconNames:[NSArray arrayWithObjects:@"Login.png",@"news.png", @"ContactCenter.png", @"AboutUs.png",nil]];

	
	//self.navigationItem.title = @"Express Data";
	CGRect frame = CGRectMake(0, 0, 400, 44);
	UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
	label.backgroundColor = [UIColor clearColor];
	label.font = [UIFont boldSystemFontOfSize:20.0];
	label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
	label.textAlignment = UITextAlignmentCenter;
	label.textColor = [UIColor orangeColor];
	label.text = @"Express Data";
	self.navigationItem.titleView = label;	
	
	self.view.backgroundColor = [UIColor clearColor];
	
	UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
	self.navigationItem.backBarButtonItem = backButton;
	[backButton release];	
	
}


/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
	
	//Initialize the toolbar
	toolbar = [[UIToolbar alloc] init];
	toolbar.barStyle = UIBarStyleDefault;
	
	//Set the toolbar to fit the width of the app
	[toolbar sizetoFit];
	
	//Calculate the height of the toolbar
	CGFloat toolbarHeight = [toolbar frame].size.height;
	
	//Get the bounds of the parent view
	CGRect rootViewBounds = self.parentViewController.view.bounds;
	
	//Get the height of the parent view
	CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
	
	//Get the width of the parent view
	CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
	
	//Get a rectangle for toolbar
	CGRect rectArea = CGRectMake(0, rootViewHeight- toolbarHeight, rootViewWidth, toolbarHeight);
	
	//Reposition and resize the receiver
	[toolbar setFrame:rectArea];
	
	//Create a button
	UIBarButtonItem *infoButton =[[UIBarButtonItem alloc] initWithTitle:@"Info" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)];
	
	[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
	
	//Add the toolbar as a subview to the navigation controller.
	[self.navigationController.view addSubview:toolbar];
	
	//Reload the table view
	[self.tableView roeloadData];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/


 // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations.
	return YES;
}
 
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
	cell.backgroundColor =[UIColor colorWithRed:205 green:201 blue:201 alpha:0.2];	
	
}


#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return NoOfSection;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [listOfItems count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return rowHeight;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
	
    }

	cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
	NSString *cellvalue = [listOfItems objectAtIndex:indexPath.row];
	[cell.textLabel setText:cellvalue];
	cell.textLabel.textColor = [UIColor whiteColor];	
	cell.textLabel.backgroundColor = [UIColor clearColor];
	
	
    NSString *cellIconName = [[self cellIconNames] objectAtIndex:[indexPath row]];
    UIImage *cellIcon = [UIImage imageNamed:cellIconName];
    [[cell imageView] setImage:cellIcon];


    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

	switch (indexPath.row) {
		case LoginRow:
		{
			
			LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController"  bundle:nil];
			[self.navigationController pushViewController:loginViewController animated:YES];
			[loginViewController release];
			break;
		}	
		case NewsCenterRow:
		{
			
			NewsCenterViewController *newsCenterViewController = [[NewsCenterViewController alloc] initWithNibName:@"NewsCenterViewController"  bundle:nil];
			[self.navigationController pushViewController:newsCenterViewController animated:YES];
			[newsCenterViewController release];
			break;
		}
		case AboutUsRow:
		{

			AboutViewController *aboutViewController = [[AboutViewController alloc] initWithNibName:@"AboutViewController"  bundle:nil];
			[self.navigationController pushViewController:aboutViewController animated:YES];
			[aboutViewController release];
			break;
		}
		case ContactRow:
		{
			//ContactCenterViewController *contactCenterViewController = [[ContactCenterViewController alloc] initWithStyle:UITableViewStyleGrouped ];
			//contactCenterViewController.tableView.sectionFooterHeight = 0;
			//contactCenterViewController.tableView.sectionHeaderHeight = 10;
			//contactCenterViewController.tableView.autoresizesSubviews = YES;
			//[self.navigationController pushViewController:contactCenterViewController animated:YES];
			//[contactCenterViewController release];
			ContactCenterMapViewController *contactMapViewController = [[ContactCenterMapViewController alloc] initWithNibName:@"ContactCenterMapViewController" bundle:nil];
			[self.navigationController pushViewController:contactMapViewController animated:YES];

			 
			break;
		}

	}
	
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
	[cellIconNames release];
	[listOfItems release];
    [super dealloc];
}


@end

